package com.example.demo.service;

import com.example.demo.mapper.UserMapper;
import com.example.demo.model.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

//    @Transactional
    public int add(Userinfo userinfo) {
        int result = userMapper.add(userinfo);
        System.out.println("add result -> " + result);
        return result;
    }

    @Transactional
    public int insert(Userinfo userinfo) {
        int result = userMapper.add(userinfo);
        System.out.println("insert result -> " + result);

        int num = 10 / 0;

//        try {
//            int num = 10 / 0;
//        } catch (Exception e) {
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//        }
        return result;
    }

}